﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace ExoticCarRental
{
    public partial class Browse : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["UserSettings"] == null)
            {
                Response.Redirect("login.aspx");
            }
            if (!IsPostBack)
            {
                BusinessLayer bl = new BusinessLayer();
                //get the email from the cookie, if cookie is empty redirect to login
                DataTable ObjectDataSource1 = bl.GetCategories();
                cboCategories.DataSource = ObjectDataSource1;
                cboCategories.DataTextField = "category_name";
                cboCategories.DataValueField = "category_id";
                cboCategories.DataBind();

                DataRow row = bl.GetCategory(Convert.ToInt32(cboCategories.SelectedValue.ToString()));
                lblCateGoryName.Text = row["category_name"].ToString();
                lblCategoryDesc.Text = row["category_desc"].ToString();
                lblDailyRate.Text = row["daily_rate"].ToString();
                lblDailyInsurance.Text = row["daily_insurance_rate"].ToString();
                imgCar.ImageUrl = row["pictureurl"].ToString();





            }
        }

        protected void cboCategories_SelectedIndexChanged(object sender, EventArgs e)
        {
            Response.Write(this.cboCategories.SelectedValue);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            BusinessLayer bl = new BusinessLayer();
            //get the email from the cookie, if cookie is empty redirect to login
            DataRow row = bl.GetCategory(Convert.ToInt32(cboCategories.SelectedValue.ToString()));
            lblCateGoryName.Text = row["category_name"].ToString();
            lblCategoryDesc.Text = row["category_desc"].ToString();
            lblDailyRate.Text = row["daily_rate"].ToString();
            lblDailyInsurance.Text = row["daily_insurance_rate"].ToString();
            imgCar.ImageUrl = row["pictureurl"].ToString(); 

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("reservation.aspx?cp=" + cboCategories.SelectedValue.ToString());
        }

     
    }
}
